#!/bin/bash

# 测试视频下载系统构建脚本

echo "🔨 构建测试视频下载系统..."

# 构建Java微服务
echo "📦 构建Java微服务..."
services=("gateway-service" "auth-service" "download-service" "parser-service" "file-service")

for service in "${services[@]}"; do
    echo "构建 $service..."
    cd $service
    if [ -f "pom.xml" ]; then
        mvn clean package -DskipTests
        if [ $? -eq 0 ]; then
            echo "✅ $service 构建成功"
        else
            echo "❌ $service 构建失败"
            exit 1
        fi
    fi
    cd ..
done

# 构建前端
echo "🌐 构建前端项目..."
cd frontend
if [ -f "package.json" ]; then
    npm install
    npm run build
    if [ $? -eq 0 ]; then
        echo "✅ 前端构建成功"
    else
        echo "❌ 前端构建失败"
        exit 1
    fi
fi
cd ..

# 构建Docker镜像
echo "🐳 构建Docker镜像..."
docker-compose build

echo "✅ 所有服务构建完成！"
echo "🚀 运行 ./start.sh 启动系统"